home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / 4utils73.zip / DISPLAYK.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-01  |  12KB  |  387 lines

  1. UNIT DisplayKeyboardAndCursor;
  2. {$D-}
  3. (* ----------------------------------------------------------------------
  4.    Part of 4DESC - A Simple 4DOS File Description Editor
  5.  
  6.        David Frey,         & Tom Bowden
  7.        Urdorferstrasse 30    1575 Canberra Drive
  8.        8952 Schlieren ZH     Stone Mountain, GA 30088-3629
  9.        Switzerland           USA
  10.  
  11.        Code created using Turbo Pascal 7.0, (c) Borland International 1992
  12.  
  13.    DISCLAIMER: This unit is freeware: you are allowed to use, copy
  14.                and change it free of charge, but you may not sell or hire
  15.                this part of 4DESC. The copyright remains in our hands.
  16.  
  17.                If you make any (considerable) changes to the source code,
  18.                please let us know. (send a copy or a listing).
  19.                We would like to see what you have done.
  20.  
  21.                We, David Frey and Tom Bowden, the authors, provide absolutely
  22.                no warranty of any kind. The user of this software takes the
  23.                entire risk of damages, failures, data losses or other
  24.                incidents.
  25.  
  26.    This unit manages displaying messages, switching cursor modes etc.
  27.  
  28.    ----------------------------------------------------------------------- *)
  29.  
  30. INTERFACE USES Crt, Dos;
  31.  
  32. CONST Header = '4DESC 1.53 - (c) 1992, 1993 Copyright by David Frey & Tom Bowden';
  33.  
  34. (* Cursor *)
  35.  
  36. VAR OrigCursor : WORD;
  37.  
  38. (* Color constants for color screens: *)
  39.  
  40. CONST co_StatusFg = Blue;
  41.       co_StatusBg = Cyan;
  42.       co_DirFg    = LightCyan;
  43.       co_SelectFg = Blue;
  44.       co_SelectBg = Cyan;
  45.       co_HighFg   = LightRed;
  46.       co_NormFg   = LightGray;
  47.       co_NormBg   = Blue;
  48.       co_WarnFg   = Yellow;
  49.       co_WarnBg   = Cyan;
  50.  
  51.       (* ..and for monochrome displays: *)
  52.  
  53.       mo_StatusFg = Black;
  54.       mo_StatusBg = LightGray;
  55.       mo_DirFg    = White;
  56.       mo_SelectFg = Black;
  57.       mo_SelectBg = LightGray;
  58.       mo_HighFg   = LightGray;
  59.       mo_NormFg   = LightGray;
  60.       mo_NormBg   = Black;
  61.       mo_WarnFg   = Black;
  62.       mo_WarnBg   = White;
  63.  
  64. VAR   ScreenSize : BYTE;
  65.       ScreenWidth: BYTE;
  66.       MaxLines   : BYTE;
  67.       Monochrome : BOOLEAN;
  68.  
  69. VAR   StatusFg   : BYTE;
  70.       StatusBg   : BYTE;
  71.       DirFg      : BYTE;
  72.       SelectFg   : BYTE;
  73.       SelectBg   : BYTE;
  74.       HighFg     : BYTE;
  75.       NormFg     : BYTE;
  76.       NormBg     : BYTE;
  77.       WarnFg     : BYTE;
  78.       WarnBg     : BYTE;
  79.       _4DOSVer   : STRING[11];
  80.  
  81.       ListCmd    : PathStr;
  82.       NotLeftJust: BOOLEAN;
  83.       FullSize   : BOOLEAN;
  84.       UseHidden  : BOOLEAN;
  85.  
  86. PROCEDURE Abort(msg: STRING);
  87.  
  88. (* Min/Max *)
  89. FUNCTION Min(a,b : INTEGER): INTEGER;
  90. FUNCTION Max(a,b : INTEGER): INTEGER;
  91.  
  92. (* Cursor *)
  93.  
  94. PROCEDURE SetCursorShape(Cursor: WORD);
  95. FUNCTION  GetCursorShape: WORD;
  96. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  97.  
  98. (* Screen *)
  99. PROCEDURE Get4DOSVer;
  100. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  101.  
  102. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  103. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD);
  104. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed: BOOLEAN);
  105. PROCEDURE ShowHelp;
  106.  
  107. (* Keyboard *)
  108.  
  109. FUNCTION GetKey: WORD;
  110.  
  111.  
  112. IMPLEMENTATION USES HandleINIFile, StringDateHandling;
  113.  
  114. VAR s   : STRING;
  115.     line: STRING[132];
  116.  
  117. PROCEDURE Abort(msg: STRING);
  118.  
  119. BEGIN
  120.  NormVideo;
  121.  ClrScr;
  122.  Write(msg);
  123.  HALT(255);
  124. END;
  125.  
  126. (*------------------------------------------------------------- Min/Max *)
  127. FUNCTION Min(a,b : INTEGER): INTEGER;
  128.  
  129. BEGIN
  130.  IF a < b THEN Min := a
  131.           ELSE Min := b;
  132. END;
  133.  
  134. FUNCTION Max(a,b : INTEGER): INTEGER;
  135.  
  136. BEGIN
  137.  IF a > b THEN Max := a
  138.           ELSE Max := b;
  139. END;
  140.  
  141.  
  142. (* -------------------------------------------------------- Cursor *)
  143.  
  144. PROCEDURE SetCursorShape(Cursor: WORD); ASSEMBLER;
  145.  
  146. ASM
  147.  mov ah,01h
  148.  mov cx,Cursor
  149.  Int 10h
  150. END;
  151.  
  152. FUNCTION  GetCursorShape: WORD; ASSEMBLER;
  153.  
  154. ASM
  155.  mov ah,03h
  156.  mov bh,0
  157.  Int 10h
  158.  mov ax,cx
  159. END;
  160.  
  161. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  162.  
  163. VAR Cursor : WORD;
  164.  
  165. BEGIN
  166.  IF Overwrite THEN Cursor := $0007
  167.               ELSE Cursor := $0607;
  168.  SetCursorShape(Cursor);
  169. END; (* ResetCursor *)
  170.  
  171.  
  172. (* -------------------------------------------------------- Screen *)
  173. PROCEDURE Get4DOSVer;
  174.  
  175. VAR Regs    : Registers;
  176.     _4dvmaj : STRING[1];
  177.     _4dvmin : STRING[2];
  178.  
  179.  PROCEDURE DisplayVer;
  180.   BEGIN
  181.    Str(Regs.bl:1,_4dvmaj);
  182.    Str(Regs.bh:2,_4dvmin);
  183.    IF _4dvmin[1] = ' ' THEN _4dvmin[1] := '0';
  184.    _4DOSVer := ' 4DOS ' + _4dvmaj + '.' + _4dvmin + ' ';
  185.   END;
  186.  
  187. BEGIN
  188.  Regs.ax := $D44D;
  189.  Regs.bx := $0;
  190.  Intr($2F,Regs);
  191.  IF Regs.ax = $44DD THEN    (* 4DOS is active *)
  192.   DisplayVer
  193.  ELSE
  194.   BEGIN
  195.    Regs.ax := $E44D;
  196.    Regs.bx := $0;
  197.    Intr($2F,Regs);
  198.    IF Regs.ax = $44EE THEN    (* NDOS is active *)
  199.     BEGIN
  200.      DisplayVer;
  201.      _4DOSVer[2] := 'N';
  202.     END
  203.    ELSE
  204.     _4DOSVer := '───────────';
  205.   END
  206. END;  (* Get4DOSVer *)
  207.  
  208. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  209.  
  210. VAR ch : WORD;
  211.  
  212. BEGIN
  213.  TextColor(WarnFg); TextBackGround(WarnBg);
  214.  GotoXY(1,MaxLines);
  215.  IF Length(msg) < ScreenWidth-1 THEN Write(Chars(' ',(ScreenWidth-Length(msg)) div 2));
  216.  Write(msg); ClrEol;
  217.  REPEAT UNTIL KeyPressed;
  218.  ch := GetKey;  (* Throw away keystroke. *)
  219.  DrawStatusLine(TRUE,FullClipBoard,Changed);
  220. END; (* ReportError *)
  221.  
  222. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed: BOOLEAN);
  223.  
  224. BEGIN
  225.  TextBackGround(NormBg);
  226.  IF Redraw THEN
  227.   BEGIN
  228.    TextColor(NormFg); ClrEol;
  229.    GotoXY(1,MaxLines); Write(line);
  230.    GotoXY(3,MaxLines); Write(_4DOSVer);
  231.   END;
  232.  
  233.  GotoXY(76,MaxLines);
  234.  IF FullClipBoard THEN BEGIN TextColor(HighFg); Write('Cut'); END
  235.                   ELSE BEGIN TextColor(NormFg); Write('───'); END;
  236.  
  237.  GotoXY(70,MaxLines);
  238.  IF Changed THEN BEGIN TextColor(HighFg); Write('Edit'); END
  239.             ELSE BEGIN TextColor(NormFg); Write('────'); END;
  240.  TextColor(NormFg); GotoXY(3,MaxLines); Write(_4DOSVer);
  241. END; (* DrawStatusLine *)
  242.  
  243. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD);
  244.  
  245. BEGIN
  246.  TextColor(NormFg); TextBackGround(NormBg);
  247.  ClrScr;
  248.  TextColor(StatusFg); TextBackGround(StatusBg);
  249.  GotoXY(1,1);
  250.  Write(' ESC exits │ ',Chr(24),' or ',Chr(25),' Selects │           │',
  251.        ' F2 or F10 Saves │ Line ',Index:5,' of ',NrOfFiles:5,' ');
  252.  DrawStatusLine(TRUE,FALSE,FALSE);
  253. END; (* DrawMainScreen *)
  254.  
  255. PROCEDURE ShowHelp;
  256.  
  257. VAR cursor, ch : WORD;
  258.  
  259. BEGIN
  260.  TextBackGround(NormBg);
  261.  ClrScr;
  262.  TextColor(DirFg);
  263.  GotoXY((ScreenWidth-10) DIV 2, 1); Write('4DESC Help');
  264.  TextColor(NormFg);
  265.  GotoXY( 8, 2); Write('USAGE:  4DESC [/help] [/mono] [d:][\path\][descript.ion]');
  266.  
  267.  GotoXY( 8, 4); Write('UpArr, DnArr, PgUp, PgDn:  Move highlight bar');
  268.  GotoXY( 8, 5); Write('LtArr, RtArr, Home, End:   Move cursor');
  269.  GotoXY( 8, 6); Write('Ctrl-PgUp, Ctrl-PgDn:      Move to first or last line');
  270.  GotoXY( 8, 7); Write('Ctrl-Left, Ctrl-Right:     Move to previous/next word');
  271.  GotoXY( 8, 9); Write('Backspace:        Delete the character before the cursor');
  272.  GotoXY( 8,10); Write('DEL:              Delete the character under  the cursor');
  273.  GotoXY( 8,11); Write('Ctrl-End:         Delete from cursor to end of line');
  274.  GotoXY( 8,12); Write('INS:              Toggle from insert mode (default) to overwrite mode ');
  275.  GotoXY( 8,13); Write('Alt-D:            Delete current description');
  276.  GotoXY( 8,14); Write('Alt-C:            Copy current description to buffer');
  277.  GotoXY( 8,15); Write('Alt-M, Alt-T:     Move current description to buffer');
  278.  GotoXY( 8,16); Write('Alt-P:            Paste buffer to current description');
  279.  GotoXY( 8,17); Write('Alt-V, F3:        View higlighted file');
  280.  GotoXY( 8,18); Write('Alt-S, Shift-F10: Shell to (4)DOS');
  281.  GotoXY( 8,19); Write('Alt-X, ESC:       Exit program');
  282.  GotoXY( 8,20); Write('F4 or ENTER on dir :  Change to highlighted directory');
  283.  GotoXY( 8,21); Write('F5 or ENTER on ..  :  Change to parent directory');
  284.  GotoXY( 8,22); Write('F6 or Alt-L        :  Change drive');
  285.  
  286.  GotoXY( 8,24); Write(Header);
  287.  GotoXY(25,25); Write('Press any key to return.');
  288.  
  289.  Cursor := $2000; SetCursorShape(Cursor);   (* Hide cursor. *)
  290.  REPEAT UNTIL KeyPressed;
  291.  ch := GetKey;             (* Throw away keystroke. *)
  292. END; (* ShowHelp *)
  293.  
  294. (* -------------------------------------------------------- Keyboard *)
  295.  
  296. FUNCTION GetKey: WORD;
  297.  
  298. VAR chlo, chhi : CHAR;
  299.  
  300. BEGIN
  301.  REPEAT UNTIL KeyPressed;
  302.  chlo := ReadKey;
  303.  IF chlo = #0 THEN chhi := ReadKey
  304.               ELSE chhi := #0;
  305.  GetKey := WORD(chhi) SHL 8 + BYTE(chlo);
  306. END;
  307.  
  308.  
  309. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  310.  
  311. BEGIN
  312.  IF Monochrome THEN
  313.   IF INIFileExists THEN
  314.    BEGIN
  315.     DirFg    := ReadSettingsColor('monodisplay','dirfg'   ,mo_DirFg);
  316.     StatusFg := ReadSettingsColor('monodisplay','statusfg',mo_StatusFg);
  317.     StatusBg := ReadSettingsColor('monodisplay','statusbg',mo_StatusBg);
  318.     SelectFg := ReadSettingsColor('monodisplay','selectfg',mo_SelectFg);
  319.     SelectBg := ReadSettingsColor('monodisplay','selectbg',mo_SelectBg);
  320.     HighFg   := ReadSettingsColor('monodisplay','highfg'  ,mo_HighFg);
  321.     NormFg   := ReadSettingsColor('monodisplay','normfg'  ,mo_NormFg);
  322.     NormBg   := ReadSettingsColor('monodisplay','normbg'  ,mo_NormBg);
  323.     WarnFg   := ReadSettingsColor('monodisplay','warnfg'  ,mo_WarnFg);
  324.     WarnBg   := ReadSettingsColor('monodisplay','warnbg'  ,mo_WarnBg);
  325.    END
  326.   ELSE
  327.    BEGIN
  328.     DirFg    := mo_DirFg;
  329.     StatusFg := mo_StatusFg; StatusBg := mo_StatusBg;
  330.     SelectFg := mo_SelectFg; SelectBg := mo_SelectBg;
  331.     HighFg   := mo_HighFg;
  332.     NormFg   := mo_NormFg;   NormBg   := mo_NormBg;
  333.     WarnFg   := mo_WarnFg;   WarnBg   := mo_WarnBg;
  334.    END
  335.  ELSE
  336.   IF INIFileExists THEN
  337.    BEGIN
  338.     DirFg    := ReadSettingsColor('colordisplay','dirfg'   ,co_DirFg);
  339.     StatusFg := ReadSettingsColor('colordisplay','statusfg',co_StatusFg);
  340.     StatusBg := ReadSettingsColor('colordisplay','statusbg',co_StatusBg);
  341.     SelectFg := ReadSettingsColor('colordisplay','selectfg',co_SelectFg);
  342.     SelectBg := ReadSettingsColor('colordisplay','selectbg',co_SelectBg);
  343.     HighFg   := ReadSettingsColor('colordisplay','highfg'  ,co_HighFg);
  344.     NormFg   := ReadSettingsColor('colordisplay','normfg'  ,co_NormFg);
  345.     NormBg   := ReadSettingsColor('colordisplay','normbg'  ,co_NormBg);
  346.     WarnFg   := ReadSettingsColor('colordisplay','warnfg'  ,co_WarnFg);
  347.     WarnBg   := ReadSettingsColor('colordisplay','warnbg'  ,co_WarnBg);
  348.    END
  349.   ELSE
  350.    BEGIN
  351.     DirFg    := co_DirFg;
  352.     StatusFg := co_StatusFg; StatusBg := co_StatusBg;
  353.     SelectFg := co_SelectFg; SelectBg := co_SelectBg;
  354.     HighFg   := co_HighFg;
  355.     NormFg   := co_NormFg;   NormBg   := co_NormBg;
  356.     WarnFg   := co_WarnFg;   WarnBg   := co_WarnBg;
  357.    END;
  358. END;
  359.  
  360. BEGIN
  361.  Get4DOSVer;
  362.  OrigCursor := GetCursorShape;
  363.  MaxLines   := Hi(WindMax)+1;
  364.  ScreenSize := MaxLines-4;
  365.  ScreenWidth:= Lo(WindMax)+1;
  366.  Monochrome := (LastMode = Mono);
  367.  line       := Chars('─',ScreenWidth-1);
  368.  
  369.  IF INIFileExists THEN
  370.   BEGIN
  371.    s := ReadSettingsString('generaldisplay','leftjust','n');
  372.    NotLeftJust := (s[1] = 'y');
  373.    s := ReadSettingsString('generaldisplay','fullsize','n');
  374.    FullSize := (s[1] = 'y');
  375.    s := ReadSettingsString('generaldisplay','hidden','n');
  376.    UseHidden:= (s[1] = 'y');
  377.    ListCmd := ReadSettingsString('generaldisplay','viewer','list')
  378.   END
  379.  ELSE
  380.   BEGIN
  381.    NotLeftJust:= FALSE;
  382.    FullSize   := FALSE;
  383.    UseHidden  := FALSE;
  384.    ListCmd    := 'list';
  385.   END;
  386. END.
  387.